<?php

namespace App\Domain\Saleman\Dao;

use App\Domain\Saleman\Models\SalemanModel;

class SalemanDao
{
    public function findById($id)
    {
        return SalemanModel::where('id', $id)->where('state','1')->first();
    }

    public function del($id){
        $ids = explode(',',$id);
        return SalemanModel::whereIn('id',$ids)->update(['state'=>'0']);
    }

    /**
     * 修改业务员
     * @param SalemanModel $model
     * @param $param
     * @return SalemanModel
     */
    public function update(SalemanModel $model, $param)
    {
        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }

    /**
     * 创建业务员
     * @param $params
     * @return SalemanModel
     */
    public function create($params)
    {
        $params = array_filter_null($params);
        return SalemanModel::create($params);
    }
}
